/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ViewJobResponseScreen.java
 *
 * Created on Oct 29, 2011, 7:36:05 PM
 */
package jobresponse;

import java.util.Date;
import java.util.Enumeration;
import java.util.Random;
import javax.swing.table.TableModel;
import jobresponse.JobResponseDAO;
import jobresponse.JobResponseDTO;
import jobadvertisement.JobAdvertisementDAO;
import jobadvertisement.JobAdvertisementDTO;
import jobseeker.JobSeekerAccountDAO;
import jobseeker.JobSeekerAccountDTO;

/**
 *
 * @author mohdalimhs
 */
public class ViewJobResponseScreen extends javax.swing.JFrame {

    private JobResponseDAO jobResponseDAO;
    private JobAdvertisementDAO jobAdsDAO;
    private JobSeekerAccountDAO jobseekerDAO;

    /** Creates new form ViewJobResponseScreen */
    public ViewJobResponseScreen() {
        initComponents();

        jobResponseDAO = new JobResponseDAO();
        jobResponseDAO.readDTOs();
        jobAdsDAO = new JobAdvertisementDAO();
        jobAdsDAO.readDTOs();
        System.out.println(jobAdsDAO.readDTOs());
        jobseekerDAO = new JobSeekerAccountDAO();
        jobseekerDAO.readDTOs();

        // Populate to combo box
        Enumeration<String> allJobAdsKeys = jobAdsDAO.getDTOHashTable().keys();
        while (allJobAdsKeys.hasMoreElements()) {
            jobAdsIDCombo.addItem((String) allJobAdsKeys.nextElement());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jobAdsIDCombo = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        applicantTable = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Job Advertisement ID");

        jobAdsIDCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jobAdsIDComboActionPerformed(evt);
            }
        });

        applicantTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Email", "Date of Birth", "Name", "Contact Number", "Application Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(applicantTable);

        jLabel2.setText("VIEW JOB RESPONSES");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jobAdsIDCombo, 0, 394, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(210, 210, 210)
                        .addComponent(jLabel2)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel2)
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jobAdsIDCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jobAdsIDComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jobAdsIDComboActionPerformed
// TODO add your handling code here:
    TableModel model = (TableModel) applicantTable.getModel();
    String currentJobAds = (String) jobAdsIDCombo.getSelectedItem();
    Enumeration<String> allJobResponseKeys = jobResponseDAO.getIDs();
    int currentRow = 0;
    while (allJobResponseKeys.hasMoreElements()) {
        // If jobresponseDTO belong to current job, add it to the table
        JobResponseDTO jobResponseDTO = jobResponseDAO.getDTO(allJobResponseKeys.nextElement());
        if (jobResponseDTO.getJobAdvertisementID().equalsIgnoreCase(currentJobAds)) {
            JobSeekerAccountDTO jobseekerDTO = jobseekerDAO.getDTO(jobResponseDTO.getJobSeekerID());
            model.setValueAt(jobseekerDTO.getEmail(), currentRow, 0);
            model.setValueAt(jobseekerDTO.getDob(), currentRow, 1);
            model.setValueAt(jobseekerDTO.getName(), currentRow, 2);
            model.setValueAt(jobseekerDTO.getContactNumber(), currentRow, 3);
            model.setValueAt(jobResponseDTO.getStatus(), currentRow, 4);
            currentRow++;
        }
    }
}//GEN-LAST:event_jobAdsIDComboActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ViewJobResponseScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ViewJobResponseScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ViewJobResponseScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ViewJobResponseScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ViewJobResponseScreen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable applicantTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jobAdsIDCombo;
    // End of variables declaration//GEN-END:variables
}
